// package com.xuyuan.ai.auto;
//
// import io.micrometer.observation.ObservationRegistry;
// import org.apache.commons.lang3.reflect.FieldUtils;
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// import org.springframework.ai.autoconfigure.chat.client.ChatClientBuilderConfigurer;
// import org.springframework.ai.autoconfigure.chat.client.ChatClientBuilderProperties;
// import org.springframework.ai.chat.client.ChatClient;
// import org.springframework.ai.chat.client.ChatClientCustomizer;
// import org.springframework.ai.chat.client.observation.ChatClientInputContentObservationFilter;
// import org.springframework.ai.chat.client.observation.ChatClientObservationConvention;
// import org.springframework.ai.chat.model.ChatModel;
// import org.springframework.beans.factory.ObjectProvider;
// import org.springframework.beans.factory.annotation.Qualifier;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
// import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
// import org.springframework.boot.context.properties.EnableConfigurationProperties;
// import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.context.annotation.Scope;
//
// /**
//  * @author xuyuan
//  * @desc 适配多种大模型，重写ChatClient.Builder的自动装配。 Chat - OpenAI(Deepseek)、Embedding - QianFan。也可以禁用千帆的ChatModel
//  * @see org.springframework.ai.autoconfigure.chat.client.ChatClientAutoConfiguration
//  */
// @Configuration
// @ConditionalOnClass({ChatClient.class})
// @EnableConfigurationProperties({ChatClientBuilderProperties.class})
// @ConditionalOnProperty(prefix = "spring.ai.chat.client", name = {"enabled"}, havingValue = "true", matchIfMissing = true)
// public class ChatClientAutoConfiguration {
//     private static final Logger logger = LoggerFactory.getLogger(ChatClientAutoConfiguration.class);
//
//     public ChatClientAutoConfiguration() {
//     }
//
//     @Bean
//     @ConditionalOnMissingBean
//     ChatClientBuilderConfigurer chatClientBuilderConfigurer(ObjectProvider<ChatClientCustomizer> customizerProvider) throws IllegalAccessException {
//         ChatClientBuilderConfigurer configurer = new ChatClientBuilderConfigurer();
//         FieldUtils.writeDeclaredField(configurer, "customizers", customizerProvider.orderedStream().toList(), true);
//         return configurer;
//     }
//
//     @Bean
//     @Scope("prototype")
//     @ConditionalOnMissingBean
//     ChatClient.Builder chatClientBuilder(ChatClientBuilderConfigurer chatClientBuilderConfigurer, @Qualifier("openAiChatModel") ChatModel chatModel, ObjectProvider<ObservationRegistry> observationRegistry, ObjectProvider<ChatClientObservationConvention> observationConvention) {
//         ChatClient.Builder builder = ChatClient.builder(chatModel, observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP), observationConvention.getIfUnique(() -> null));
//         return chatClientBuilderConfigurer.configure(builder);
//     }
//
//     @Bean
//     @ConditionalOnMissingBean
//     @ConditionalOnProperty(prefix = "spring.ai.chat.client.observations", name = {"include-input"}, havingValue = "true")
//     ChatClientInputContentObservationFilter chatClientInputContentObservationFilter() {
//         logger.warn("You have enabled the inclusion of the input content in the observations, with the risk of exposing sensitive or private information. Please, be careful!");
//         return new ChatClientInputContentObservationFilter();
//     }
// }
